﻿using MediatR;
using System;
using SystemHYS.API.Application.command.DeliveryCommand;
using SystemHYS.Domian;
using SystemHYS.Infrstructre.Interface;
namespace SystemHYS.API.Application.commandler.DeliveryCommandler
{
    public class DeliveryCreateCommandler : IRequestHandler<DeliveryCreateCommand, int>
    {
        IDeliveryRepository deliveryRepository;
        public DeliveryCreateCommandler(IDeliveryRepository deliveryRepository)
        {
            this.deliveryRepository = deliveryRepository;                    
        }
        public async Task<int> Handle(DeliveryCreateCommand request, CancellationToken cancellationToken)
        {
            var list = new Delivery
            {
                deliveryName = request.deliveryName,
                deliveryNumber = request.deliveryNumber,
                deliveryDate = request.deliveryDate.ToUniversalTime(),
                orderNumber = request.orderNumber,
                remark = request.remark,
                finishedProductName = request.finishedProductName,
                finishedProductNumber = request.finishedProductNumber,
                specification = request.specification,
                unit = request.unit,
                productionNumber = request.productionNumber,
                outboundQuantity = request.outboundQuantity,
                warehouseName = request.warehouseName,
                dateTime = request.dateTime.Value.ToUniversalTime(),
                warehousePerson = request.warehousePerson,
                AddName = "李明",
                AddTime= DateTime.Now.ToUniversalTime(),
            };
            return await deliveryRepository.AddAsyn(list);
        }
    }
}
